/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seari.weixin_app_tools.main;

import com.seari.weixin_app_tools.bean.DataConfig;
import com.seari.weixin_app_tools.utils.ImportExcelUtil;
import com.seari.weixin_app_tools.utils.MiscTools;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Rainbow
 */
public class MainController
{
    protected static Logger logger = LoggerFactory.getLogger(MainController.class);
    public static Properties properties;
    public static String configPath = "config.cfg"; //配置文件路径
    public static void main(String[] args) throws Exception
    {
        MainController mainController = new MainController();
        mainController.init();
        //初始化配置类
        DataConfig dataConfig = new DataConfig();
        dataConfig.setSheetNum(Integer.parseInt(properties.getProperty("sheetNum", "1")) - 1); //程序中以0为起始，需减1
        dataConfig.setDataStartLineNum(Integer.parseInt(properties.getProperty("dataStartLineNum", "2")) - 1);
        dataConfig.setDataEndLineNum(Integer.parseInt(properties.getProperty("dataEndLineNum", "2")) - 1);
        dataConfig.setColumnStrings(properties.getProperty("columnStrings").split(","));
        dataConfig.setInputFileName(properties.getProperty("inputFileName"));
        dataConfig.setOutputFileName(properties.getProperty("outputFileName"));
        dataConfig.setShanghaiFilterStrings(properties.getProperty("shanghaiFilterStrings").split(","));
        dataConfig.setHubeiFilterStrings(properties.getProperty("hubeiFilterStrings").split(","));
        dataConfig.setOtherImportantAreaFilterStrings(properties.getProperty("otherImportantAreaFilterStrings").split(","));
        logger.info("init completed,{}",dataConfig.toString());
        //读取输入表格
        InputStream inputStream = new FileInputStream(new File(dataConfig.getInputFileName()));
        Workbook workbook = ImportExcelUtil.getWorkbook(inputStream, dataConfig.getInputFileName());
        KaoqinCounter kaoqinCounter = new KaoqinCounter(dataConfig , workbook);
        new Thread(kaoqinCounter).start();
    }
    
    private void init()
    {
        try
        {
            properties = MiscTools.loadConfig(configPath);
        } catch (Exception e)
        {
            logger.warn("init failed");
            e.printStackTrace();
            System.exit(0);
        }
    }
}
